# encoding=utf-8

# sys.path.append("../main")
# https://blog.csdn.net/songzhilian22/article/details/49636725
# https://www.libinx.com/2018/text-classification-classic-ml-by-sklearn/

import pandas as pd

import os
os.path

import src.core.PandasUtils as pandasutils
import src.core.tf_idf as tfidf
import src.core.CacheUtils as cacheutils

data = pd.read_csv("../../data/training.csv")

values = data.head(1000).values
# values = data.values

# 做数据的特征工程
path = '../../dist/train_data_1000.pkl'
if cacheutils.model_exist(path):
    print("load model from ", path)
    df = cacheutils.load_model(path)
else:
    print("start data conversion")
    df = pandasutils.convert2KeywordsDataframs(values)
    cacheutils.save_model(df, path)

# print(df["X"])
# print(df["y"])

import src.core.train as mytrain
import numpy as np

y_train = df["y"]
X_train = np.array(df["X"])

print(">>>> SVM")
model = mytrain.fit_svm(X_train, y_train)
mytrain.printmetrics(model, X_train, y_train)

print(">>>> LR")
model2 = mytrain.fit_LR(X_train, y_train)
mytrain.printmetrics(model2, X_train, y_train)

print(">>>> XGBOOST")
model3 = mytrain.fit_xgb(X_train, y_train)
mytrain.printmetrics(model3, X_train, y_train)